let info = document.querySelector(".info");
let comment = document.querySelector(".comment .contentAll .content")


let url = decodeURI(location.href).split("?")[1].split("=")[1];
console.log(url);

let pBox = localStorage.getItem("pbox");
let nav = document.querySelector("#nav .pbox");
nav.innerHTML = pBox;

const xhr1 = new XMLHttpRequest();
xhr1.open("get","http://chst.vip:1234/api/getproduct?productid="+url,true);
xhr1.onload = function(){
    if(xhr1.status === 200){
        let res1 = JSON.parse(xhr1.responseText);
        console.log(res1);

        let infos = "";
        res1.result.forEach(item => {
            infos += `<div class="pic">
                        ${item.productImg}
                    </div>
                    <div class="title">
                        ${item.productName}
                    </div>
                    <div class="count">
                    <div class="row">
                        <div class="col">
                            <span>当前最低</span>
                            <span>￥9000</span>
                        </div>
                        <div class="col">
                            <span>优选评论</span>
                            <span>9000条</span>
                        </div>
                    </div>
                </div>`
        });
        info.innerHTML = infos;
    }
}
xhr1.send(null);

const xhr2 = new XMLHttpRequest();
xhr2.open("get","http://chst.vip:1234/api/getproductcom?productid="+url,true);
xhr2.onload = function(){
    if(xhr2.status === 200){
        let res2 = JSON.parse(xhr2.responseText);
        console.log(res2);

        let comments = "";
        res2.result.forEach(item => {
            comments += `<div class="top">
                            <span class="left">
                                ${item.comName}
                            </span>
                            <span class="right">
                                ${item.comTime}
                            </span>
                        </div>
                        <div class="center">
                            ${item.comContent}
                        </div>
                        <div class="bottom">
                            ${item.comFrom}
                        </div>`
        });
        comment.innerHTML = comments;
    }
}
xhr2.send(null);
